package Java道题;

import java.util.Scanner;

//求最大公约数有三种方法

public class BigDivisor {
    public static void Divisor_1(int n1,int n2){
        int divisor;
        if(n2>n1)
        {
            int tmp=n1;
            n1=n2;
            n2=tmp;
        }

        while(n2!=0)
        {
            divisor=n1%n2;
            n1=n2;
            n2=divisor;
        }
        System.out.println(" 最大公约数："+n1);
    }


    public static void Divisor_2(int n1,int n2){
        int divisor;
        if(n2>n1)
        {
            int tmp=n1;
            n1=n2;
            n2=tmp;
        }

        while(n2!=0)
        {
            divisor=n1-n2;
            if(divisor>n2)
            {
                n1=divisor;
                n2=n2;
            }
            else
            {
                n1=n2;
                n2=divisor;

            }

        }
        System.out.println(" 最大公约数："+n1);
    }

    public static void Divisor_3(int n1,int n2){
        int divisor=2;
        int k=1;

        while(divisor<=n1&&divisor<=n2)
        {

            if(n1%divisor==0&&n2%divisor==0)
                k=divisor;
            divisor++;
        }
        System.out.println(" 最大公约数："+k);


    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner ss=new Scanner(System.in);
        System.out.println("请输入两个数：");
        int n1=ss.nextInt();
        int n2=ss.nextInt();
        //Divisor_1(n1,n2);
        //Divisor_2(n1,n2);
        Divisor_3(n1,n2);

    }

}
